package com.itcast.controller;

import com.itcast.pojo.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class SessionController {
    //设置session
    @GetMapping("/s1")
    public Result session1(HttpSession session){
        log.info("session1:{}",session.hashCode());
        session.setAttribute("login_username","zhangsan");
        return Result.success();
    }
    //获取session
    @GetMapping("/s2")
    public Result session2(HttpServletRequest request){
        HttpSession session = request.getSession();
        log.info("session2:{}",session.hashCode());
        Object value = session.getAttribute("login_username");
        System.out.println(value);
        return Result.success(value);
    }
}
